package com.yang.rabbitmqprovider.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yanwei.yang
 * @date 2020/4/2 15:47
 * @description: DirectRabbitConfig  直连型交换机  消费者单纯的使用，其实可以不用添加这个配置，直接建后面的监听就好，使用注解来让监听器监听对应的队列即可
 */
@Configuration
public class DirectRabbitConfig {


    /**
     * TestDirectQueue 队列名：TestDirectQueue
     *
     * @return Queue
     */
    @Bean
    public Queue testDirectQueue() {
        return new Queue("TestDirectQueue", true);
    }

    /**
     * 交换机：TestDirectExchange
     *
     * @return DirectExchange
     */
    @Bean
    DirectExchange testDirectExchange() {
        return new DirectExchange("TestDirectExchange");
    }

    /**
     * 绑定 将队列和交换机绑定, 并设置用于匹配键：TestDirectRouting
     *
     * @return Binding
     */
    @Bean
    Binding bindingDirect() {
        return BindingBuilder.bind(testDirectQueue()).to(testDirectExchange()).with("TestDirectRouting");
    }


    @Bean
    DirectExchange lonelyDirectExchange() {
        return new DirectExchange("lonelyDirectExchange");

    }

}
